package com.oracle.malldemo.view;



import java.io.Serializable;


public class JsonData implements Serializable,Cloneable {

    private int code; //服务器返回的状态码
    private String msg; //服务器返回的消息。
    private Object data; //服务器返回的数据

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    //表示请求成功
    public static JsonData success(){
        JsonData result = new JsonData();
        result.setCode(200);
        return result;
    }

    public static JsonData success(String msg){
        JsonData result = new JsonData();
        result.setCode(200);
        result.setMsg(msg);
        return result;
    }

    public static JsonData success(String msg,Object data){
        JsonData result = new JsonData();
        result.setCode(200);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static JsonData fail(){
        JsonData result = new JsonData();
        result.setCode(400);
        return result;
    }

    public static JsonData fail(String msg){
        JsonData result = new JsonData();
        result.setCode(400);
        result.setMsg(msg);
        return result;
    }

    public static JsonData fail(String msg,Object data){
        JsonData result = new JsonData();
        result.setCode(400);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static JsonData unauth(){
        JsonData result = new JsonData();
        result.setCode(401);
        return result;
    }

    public static JsonData unauth(String msg){
        JsonData result = new JsonData();
        result.setCode(401);
        result.setMsg(msg);
        return result;
    }

    public static JsonData unauth(String msg,Object data){
        JsonData result = new JsonData();
        result.setCode(401);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }
}
